home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _ED36BE35E94D49AEBC8850139CED709B < prev    next >
Encoding:
Text File  |  2004-01-06  |  2.2 KB  |  69 lines

  1. // ===============================================================
  2. // Vertex Program: Indoor water volume using reflection cube map
  3. // Description: used for indoor water volumes
  4. // Last Update: 19/10/2003
  5. // Coder: Tiago Sousa
  6. // ===============================================================
  7.  
  8. #include "../CGVPMacro.csi"
  9.  
  10. VertAttributes 
  11.   POSITION_3 
  12.   TEXCOORD0_2 
  13.   PRIM_COLOR 
  14.   TANG_3X3 
  15. }
  16.  
  17. MainInput 
  18.   VIEWPROJ_MATRIX, 
  19.   uniform float3x4 ObjToCubeSpace, 
  20.   uniform float3 CameraPos, 
  21.   uniform float BumpScale,
  22.   uniform float4 AnimProperties
  23. }
  24.  
  25. DeclarationsScript
  26. {
  27.   IN_T0_C0_TANG
  28.   OUT_T0_T1_T2_T3_C0
  29. }
  30.  
  31. PositionScript = PosCommon
  32.  
  33. CoreScript
  34. {
  35.   float2 fShear= float2(cos(AnimProperties.x*AnimProperties.w), sin(AnimProperties.y*AnimProperties.w));
  36.   
  37.   // pass texture coordinates for fetching the normal map  
  38.   OUT.Tex0.xy = IN.TexCoord0.xy+fShear.xy*0.01;
  39.  
  40.   // compute the 3x3 tranform from tangent space to object space
  41.   float3x3 objToTangentSpace;
  42.   // first rows are the tangent and binormal scaled by the bump scale
  43.   objToTangentSpace[0] = BumpScale * IN.Tangent;
  44.   objToTangentSpace[1] = BumpScale * IN.Binormal;
  45.   objToTangentSpace[2] = IN.TNormal;
  46.  
  47.   // compute the 3x3 transform from tangent space to cube space:
  48.   // TangentToCubeSpace = object2cube * tangent2object
  49.   //              = object2cube * transpose(objToTangentSpace) (since the inverse of a rotation is its transpose)
  50.   // so a row of TangentToCubeSpace is the transform by objToTangentSpace of the corresponding row of ObjToCubeSpace
  51.   OUT.Tex1.xyz = mul(objToTangentSpace, ObjToCubeSpace[0].xyz);
  52.   OUT.Tex2.xyz = mul(objToTangentSpace, ObjToCubeSpace[1].xyz);
  53.   OUT.Tex3.xyz = mul(objToTangentSpace, ObjToCubeSpace[2].xyz);
  54.  
  55.   // compute the eye vector (going from shaded point to eye) in cube space
  56.   float3 eyeVector = CameraPos.xyz - vPos.xyz;
  57.   OUT.Tex1.w = dot(eyeVector, ObjToCubeSpace[0].xyz);
  58.   OUT.Tex2.w = dot(eyeVector, ObjToCubeSpace[1].xyz);
  59.   OUT.Tex3.w = dot(eyeVector, ObjToCubeSpace[2].xyz);
  60.  
  61.   // output color and fresnel term hack             
  62.   float4 vHPos = mul(ModelViewProj, vPos);      
  63.       
  64.   OUT.Color.xyz = IN.Color.xyz;
  65.   OUT.Color.w = IN.Color.w*(vHPos.w*0.15);
  66. }
  67.